//
//  KSFileFolderFunc.m
//  KSLib
//
//  Created by User on 9/10/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "KSFolderFunc.h"


@implementation KSFolderFunc


//get current directory path
- (NSString *) getCurrentDirectoryPath{
    NSFileManager *filemng = [NSFileManager defaultManager];
    NSString *retPath = [filemng currentDirectoryPath];
    [filemng release];
    return retPath;
}


//get current application document directory path
 - (NSString *) getDocumentDirectoryPath;{
     NSArray *arrPath =
     NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                         NSUserDomainMask
                                         ,YES);
     
     return [arrPath objectAtIndex:0];    
 }
 
//get temporary directory path
 - (NSString *) getTempDirectoryPath{
     
     return NSTemporaryDirectory();
 }
 

//get home directory path
 - (NSString *) getHomeDirectoryPath{
     return NSTemporaryDirectory();
 }


//listing of contents of a directory
- (NSArray *) getDirectoryListing:(NSString *)prmDirectoryPath{
    
    NSFileManager *filemng = [NSFileManager defaultManager];
    NSArray *arrFiles = [filemng contentsOfDirectoryAtPath:prmDirectoryPath error:NULL];
    [filemng release];
    return arrFiles;
}

//file count in a directory
- (int) getDirectoryListingCount:(NSString *)prmDirectoryPath{
    NSFileManager *filemng = [NSFileManager defaultManager];
    NSArray *arrFiles = [filemng contentsOfDirectoryAtPath:prmDirectoryPath error:NULL];
    [filemng release];
    return [arrFiles count];
}

//Create folder
- (BOOL) createFolder:(NSString *)prmDirectoryPath{
    
    NSFileManager *filemng = [NSFileManager defaultManager];
    
    BOOL retVal = [filemng createDirectoryAtPath:prmDirectoryPath withIntermediateDirectories:YES attributes:nil error:NULL];
    
    [filemng release];
    return retVal;
    
}

//Delete folder
- (BOOL) deleteFolder:(NSString *)prmDirectoryPath{
    
    NSFileManager *filemng = [NSFileManager defaultManager];
    
    BOOL retVal = [filemng removeItemAtPath:prmDirectoryPath error:NULL];
    
    [filemng release];
    return retVal;
}

@end
